import { get, set } from '@/utils/storage'
const userModule = {
  namespaced: true,
  state () {
    return {
      // 防止刷新页面token消失,可以从本地读取,提升用户体验
      token: get('token'),
      refreshToken: get('refreshToken'),
      userInfo: {
        photo: get('photo')
      }
    }
  },
  mutations: {
    setUserInfo (state, userObj) {
      state.userInfo = {
        ...state.userInfo,
        ...userObj
      }
      set('photo', userObj.photo)
    },
    setToken (state, tokenStr) {
      state.token = tokenStr
      // 将token保存到本地
      set('token', tokenStr)
    },
    setRefreshToken (state, refreshtokenStr) {
      state.refreshToken = refreshtokenStr
      set('refreshToken', refreshtokenStr)
    }
  }
}
export default userModule
